package com.tx.admin.noveldictdetail.controller;

import com.tx.core.common.annotation.DebounceIgnore;
import com.tx.core.common.entity.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import com.tx.admin.noveldictdetail.service.NovelDictDetailService;
import com.tx.admin.noveldictdetail.pojo.dto.NovelDictDetailCreateDTO;
import com.tx.admin.noveldictdetail.pojo.dto.NovelDictDetailUpdateDTO;
import com.tx.admin.noveldictdetail.pojo.dto.NovelDictDetailListDTO;
import com.tx.admin.noveldictdetail.pojo.vo.NovelDictDetailVO;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 字典详情 Controller
 * </p>
 *
 * @author sz-admin
 * @since 2025-05-06
 */
@Tag(name =  "字典详情")
@RestController
@RequestMapping("novel-dict-detail")
@RequiredArgsConstructor
public class NovelDictDetailController  {

    private final NovelDictDetailService novelDictDetailService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "novel.dict.detail.create")
    @PostMapping
    public ApiResult<Void> create(@RequestBody NovelDictDetailCreateDTO dto) {
        novelDictDetailService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "novel.dict.detail.update")
    @PutMapping
    public ApiResult<Void> update(@RequestBody NovelDictDetailUpdateDTO dto) {
        novelDictDetailService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @SaCheckPermission(value = "novel.dict.detail.remove")
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        novelDictDetailService.remove(dto);
        return ApiResult.success();
    }

    //字典详情不限制
    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "novel.dict.detail.query_table")
    @GetMapping
    public ApiResult<PageResult<NovelDictDetailVO>> list(NovelDictDetailListDTO dto) {
        dto.setLimit(Integer.MAX_VALUE);
        return ApiPageResult.success(novelDictDetailService.page(dto));
    }

//    @DebounceIgnore
//    @Operation(summary = "小说字典查询-全部")
//    @GetMapping("dict")
//    public ApiResult<Map<String, List<DictVO>>> listDict() {
//        return ApiResult.success(sysDictService.dictAll());
//    }

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "novel.dict.detail.query_table")
    @GetMapping("/byCode")
    public ApiResult<List<NovelDictDetailVO>> getDetailsByCode(@Param("code") String code) {
        List<NovelDictDetailVO> detailsByCode = novelDictDetailService.getDetailsByCode(code);
        return ApiResult.success(detailsByCode);
    }


    @Operation(summary = "详情")
    @SaCheckPermission(value = "novel.dict.detail.query_table")
    @GetMapping("/{id}")
    public ApiResult<NovelDictDetailVO> detail(@PathVariable Object id) {
        return ApiResult.success(novelDictDetailService.detail(id));
    }

    @Operation(summary = "导入")
    @Parameters({
      @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "novel.dict.detail.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        novelDictDetailService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "novel.dict.detail.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody NovelDictDetailListDTO dto, HttpServletResponse response) {
        novelDictDetailService.exportExcel(dto, response);
    }
}